#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author : liuyu
# date : 2018/7/17 0017

from __future__ import absolute_import, unicode_literals
from celery import shared_task
from .models import AssetInfo
from utils import ansibel_tasks



@shared_task
def asset_hardware_info(*args,**kwargs):
    hostip=kwargs.get("hostip")
    if hostip:
        return ansibel_tasks.update_hardware_infos(hostip)
    else:
        i_list=AssetInfo.objects.all().values_list("network_ip")
        t_list=[]
        for i in i_list:
            results=ansibel_tasks.update_hardware_infos(i[0])
            try:
                t_list.append(results.copy())
            except:
                pass

        return t_list



